from schablonesk.logic.const_true import ConstTrue
from .branches_block import BranchesBlock


class IfBlockBuilder(object):
    
    def __init__(self, condition, block):
        self.__branches = []
        self.__branches.append((block, condition))
        
    def add_elseif(self, condition, block):
        self.__branches.append((block, condition))
        return self
    
    def add_else(self, block):
        self.__branches.append((block, ConstTrue()))
        return self
        
    def build(self):
        branches = BranchesBlock()
        for block, condition in self.__branches:
            branches.add_branch(block, condition)
        return branches
    
        
